﻿// https://mp.weixin.qq.com/s?__biz=MzUxNjY5NTYxNA==&mid=2247489352&idx=2&sn=743bd14f974eb33b70d531b3b1eb1e98&scene=21#wechat_redirect
// https://leetcode-cn.com/problems/two-sum/

#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;

// struct ListNode {
//     int val;
//     ListNode *next;
//     ListNode() : val(0), next(nullptr) {}
//     ListNode(int x) : val(x), next(nullptr) {}
//     ListNode(int x, ListNode *next) : val(x), next(next) {}
// };

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> num_map;

        for (int i = 0; i < nums.size(); i++) {
            auto iter = num_map.find(target - nums[i]);
            if (iter != num_map.end()) {
                return {iter->second, i};
            }
            num_map.insert(make_pair(nums[i], i));
        }
        return {};
    }
};

int main() {
    Solution obj = Solution();
}